package org.xiaov.common.convert;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 描述：
 * </p>
 *
 * @author xiaovcloud
 * @since 2021/9/25 17:27
 */
public enum ColumnType {
    /**
     * 数据库类型-Java类型-Java实体需要导入的类
     */
    TINYINT("tinyint", "Integer", null),
    SMALLINT("smallint", "Integer", null),
    MEDIUMINT("mediumint", "Integer", null),
    INT("int", "Integer", null),
    INTEGER("integer", "Integer", null),
    BIGINT("bigint", "Long", null),
    FLOAT("float", "Float", null),
    DOUBLE("double", "Double", null),
    DECIMAL("decimal", "BigDecimal", "java.math.BigDecimal"),
    BIT("bit", "Boolean", null),
    CHAR("char", "String", null),
    VARCHAR("varchar", "String", null),
    TINYTEXT("tinytext", "String", null),
    TEXT("text", "String", null),
    MEDIUMTEXT("mediumtext", "String", null),
    LONGTEXT("longtext", "String", null),

    DATE("date", "Date", "java.sql.Date"),
    DATETIME("datetime", "Date", "java.sql.Date"),
    TIMESTAMP("timestamp", "Date", "java.sql.Date"),
    CLOB("CLOB", "String", null),
    BLOB("BLOB", "String", null),

    NUMBER("NUMBER", "Integer", null),
    BINARY_INTEGER("BINARY_INTEGER", "Integer", null),
    BINARY_FLOAT("BINARY_FLOAT", "Float", null),
    BINARY_DOUBLE("BINARY_DOUBLE", "Double", null),
    VARCHAR2("VARCHAR2", "String", null),
    NVARCHAR("NVARCHAR", "String", null),
    NVARCHAR2("NVARCHAR2", "String", null),
    INT8("int8", "Long", null),
    INT4("int4", "Integer", null),
    INT2("int2", "Integer", null),
    NUMERIC("numeric", "BigDecimal", "java.math.BigDecimal"),
    ;

    private final String dbColumn;
    private final String javaColumn;
    private final String packPath;

    ColumnType(String dbColumn, String javaColumn, String packPath) {
        this.dbColumn = dbColumn;
        this.javaColumn = javaColumn;
        this.packPath = packPath;
    }

    public String getDbColumn() {
        return dbColumn;
    }

    public String getJavaColumn() {
        return javaColumn;
    }

    public String getPackPath() {
        return packPath;
    }

    private static final Map<String, ColumnType> DB_COLUMN_MAP;

    static {
        DB_COLUMN_MAP = new HashMap<>();
        ColumnType[] values = ColumnType.values();
        for (ColumnType column : values) {
            DB_COLUMN_MAP.put(column.getDbColumn(), column);
        }
    }

    public static ColumnType getType(String dbColumn) {
        return DB_COLUMN_MAP.get(dbColumn);
    }
}
